package config

import (
	"net/url"
	"os"

	"gitee.com/mkwchecking/sr-core/utils/ip"
)

type Application struct {
	Id       string            `json:"id"`       // 服务id
	Name     string            `json:"name"`     // 服务名称
	Mode     string            `json:"mode"`     // debug, release
	Hostname string            `json:"hostname"` // default use os.Hostname
	Version  string            `json:"version"`  // default use git tag
	Endpoint string            `json:"endpoint"` // default use local ip
	Meta     map[string]string `json:"meta"`     // custom meta
}

func (a Application) GetEndpoint() *url.URL {
	u, _ := url.Parse(a.Endpoint)
	return u
}

func defaultAppcfg() *Application {
	c := &Application{
		Mode: "debug",
		Name: "",
		Meta: make(map[string]string),
	}

	c.Hostname, _ = os.Hostname()
	c.Version = "v0.0.0"
	c.Endpoint = ip.GetLocalHost()

	return c
}
